﻿namespace FBGraphApi.Testing
{
    using System;
    using System.Windows.Forms;
    using System.Text;

    public partial class Form1 : Form
    {
        private FBApplication app;

        public Form1()
        {
            InitializeComponent();
        }

        private void fbAuthorizationBrowser1_AuthorizationSuccessful(object sender, FBGraphApi.Desktop.FBAuthorizationSuccessfulEventArgs e)
        {
            app = new FBApplication(e.AccessToken);

            try
            {

                StringBuilder sb = new StringBuilder();
                sb.AppendFormat("ID: {0}\r\n", app.CurrentUser.Id);
                sb.AppendFormat("First Name: {0}\r\n", app.CurrentUser.FirstName);
                sb.AppendFormat("Last Name: {0}\r\n", app.CurrentUser.LastName);
                sb.AppendFormat("Name: {0}\r\n", app.CurrentUser.Name);
                sb.AppendFormat("Profile Link: {0}\r\n", app.CurrentUser.Link);
                sb.AppendFormat("Birthday: {0}\r\n", app.CurrentUser.Birthday);
                sb.AppendFormat("Email: {0}\r\n", app.CurrentUser.Email);
                sb.AppendFormat("Gender: {0}\r\n", app.CurrentUser.Gender);
                sb.AppendFormat("About: \r\n{0}\r\n\r\n", app.CurrentUser.AboutMe);
                sb.AppendFormat("Bio: {0}\r\n", app.CurrentUser.Bio);
                sb.AppendFormat("Favorite Quotes: {0}\r\n", app.CurrentUser.Quotes);
                sb.AppendFormat("Religion: {0}\r\n", app.CurrentUser.Religion);
                sb.AppendFormat("Political: {0}\r\n", app.CurrentUser.PoliticalView);
                sb.AppendFormat("Location: {0} ({1})\r\n", app.CurrentUser.Location.Name, app.CurrentUser.Location.Id);
                sb.AppendFormat("Hometown: {0} ({1})\r\n", app.CurrentUser.Hometown.Name, app.CurrentUser.Hometown.Id);
                sb.AppendFormat("Friends: {0}\r\n", app.CurrentUser.Friends.Count);
                foreach (FBIdNameObject friend in app.CurrentUser.Friends)
                {
                    //sb.AppendFormat("{0} ({1})\r\n", friend.Name, friend.Id);
                    User u = app.GetUser(friend.Id);
                    sb.AppendFormat("{0} ({1}): {2}\r\n ", u.Id, u.Name, u.AboutMe);
                }
                MessageBox.Show(sb.ToString());

                sb = new StringBuilder();
                foreach (FBStreamObject so in app.CurrentUser.NewsFeed)
                {
                    sb.AppendFormat("ID: {0}, Likes: {4}, From: {1} ({2}), {3}\r\n", so.Id, so.From.Name, so.From.Id, so.CreatedTime.ToString(), so.Likes);
                }
                MessageBox.Show(sb.ToString());
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            fbAuthorizationBrowser1.StartAuthorize();
        }
    }
}
